//
//  GKDYHomeViewController.m
//  GKDYVideo
//
//  Created by QuintGao on 2018/9/23.
//  Copyright © 2018 QuintGao. All rights reserved.
//

#import "LYouHomeViewController.h"
#import "LYouPlayerViewController.h"
#import "LYouSettingViewController.h"
#import "LYouSearchViewController.h"
#import "LYouDetailController.h"
#import "LYouBuyMemberController.h"

@interface LYouHomeViewController()

@property (nonatomic, strong) LYouPlayerViewController  *playerVC;

@end

@implementation LYouHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    /** 注册通知 */
    WeakSelf(weakSelf);
    [self addObserverForName:@"LYouUpdateFavorStater" block:^(NSNotification * _Nullable note){
        NSString *isFavor = note.userInfo[@"isFavor"];
        if ([isFavor isEqualToString:@"1"]) {
            /** 收藏 */
            weakSelf.playerVC.videoView.currentPlayView.favoriteBtn.selected = YES;
        }else{
            weakSelf.playerVC.videoView.currentPlayView.favoriteBtn.selected = NO;
        }
    }];
    
    self.gk_navigationBar.hidden    = YES;
    [self.view addSubview:self.playerVC.view];
    self.playerVC.pushToSetVCBlock = ^(){
        
        LYouSettingViewController *setVC = [[LYouSettingViewController alloc]init];
        [weakSelf.navigationController pushViewController:setVC animated:YES];
    };
    self.playerVC.pushToSearchVCBlock = ^(){
        LYouSearchViewController *searchVC = [[LYouSearchViewController alloc]init];
        [weakSelf.navigationController pushViewController:searchVC animated:YES];
    };
    self.playerVC.pushToDetailVCBlock = ^(LYouVideoModel * _Nonnull model) {
        LYouDetailController *detailVC = [[LYouDetailController alloc]init];
        detailVC.model = model;
        [weakSelf.navigationController pushViewController:detailVC animated:YES];
    };
    self.playerVC.pushToBuyMemVCBlock = ^(NSString *isCheck) {
        /** 是否跳转到订购页面 */
        if ([isCheck isEqualToString:@"no"]&&[ISHAVEBUYMEMBER isEqualToString:@"no"]) {
            /** 跳转到购买会员页 */
            LYouBuyMemberController *buyVC = [[LYouBuyMemberController alloc]init];
            [weakSelf.navigationController pushViewController:buyVC animated:YES];
        }
    };
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.gk_statusBarHidden = YES;
    [self.playerVC.videoView resume];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self.playerVC.videoView pause];
}

#pragma mark - 懒加载
- (LYouPlayerViewController *)playerVC {
    if (!_playerVC) {
        _playerVC = [LYouPlayerViewController new];
        _playerVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    }
    return _playerVC;
}



@end
